package com.jibei.mendo.utils;

import com.jibei.mendo.event.Event;
import com.jibei.mendo.event.IEvent;

import org.greenrobot.eventbus.EventBus;

/**
 * Created by Devin on 2019/8/11.
 */
public class EventBusUtil implements IEvent {

    private EventBus mEventBus;

    private EventBusUtil() {
        mEventBus = EventBus.getDefault();
    }

    public static EventBusUtil getInstance() {
        return EventBusUtil.Holder.instance;
    }

    private static class Holder {
        private static final EventBusUtil instance = new EventBusUtil();
    }

    @Override
    public void postEvent(Event mEvent) {
        mEventBus.post(mEvent);
    }

    @Override
    public void postStickEvent(Event event) {
        mEventBus.postSticky(event);
    }

    @Override
    public void register(Object context) {
        if (!mEventBus.isRegistered(context)) {
            mEventBus.register(context);
        }
    }

    @Override
    public void unregister(Object context) {
        if (mEventBus.isRegistered(context)) {
            mEventBus.unregister(context);
        }
    }
}

